package com.tjf.lib_utils;


import com.tjf.lib_utils.bean.BusEvent;

import org.greenrobot.eventbus.EventBus;

/**
 * @author: tjf
 * @date: 2023-06-20
 * @desc： EventBus帮助类
 */

public class EventBusUtils {

    /**
     * 注册事件
     */
    public static void register(Object subscriber) {
        EventBus.getDefault().register(subscriber);
    }

    /**
     * 解除事件
     */
    public static void unregister(Object subscriber) {
        EventBus.getDefault().unregister(subscriber);
    }

    /**
     * 发送普通事件
     */
    public static void sendEvent(BusEvent event) {
        EventBus.getDefault().post(event);
    }

    /**
     * 发送粘性事件
     */
    public static void sendEventSticky(BusEvent event) {
        EventBus.getDefault().postSticky(event);
    }

    /**
     * 发送普通事件
     */
    public static void sendEvent(String action) {
        sendEvent(new BusEvent<String>(action));
    }

    /**
     * 发送普通事件
     */
    public static void sendEvent(String action, Object data) {
        sendEvent(new BusEvent<>(action, data));
    }

    /**
     * 发送粘性事件
     */
    public static void sendEventSticky(String action, Object data) {
        sendEventSticky(new BusEvent<>(action, data));
    }

    /**
     * 发送普通事件
     */
    public static void sendEvent(String action, int actionStatus, Object data) {
        sendEvent(new BusEvent<>(action, actionStatus, data));
    }

    /**
     * 发送普通事件
     */
    public static void sendEvent(String action, int actionStatus, String msg, Object data) {
        sendEvent(new BusEvent<>(action, actionStatus, msg, data));
    }

}
